package com.yugao.fintech.antelope.pay.payment.controller.refund;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yugao.fintech.antelope.base.log.OperateLog;
import com.yugao.fintech.antelope.pay.common.annotation.PayCheck;
import com.yugao.fintech.antelope.pay.common.service.RefundOrderService;
import com.yugao.fintech.antelope.pay.model.rqrs.RefundOrderQL;
import com.yugao.fintech.antelope.pay.model.rqrs.pay.refund.RefundOrderRQ;
import com.yugao.fintech.antelope.pay.model.rqrs.pay.refund.RefundOrderRS;
import com.yugao.fintech.antelope.pay.payment.process.refund.RefundOrderProcess;
import com.yugao.fintech.antelope.base.ram.ActionType;
import com.yugao.fintech.antelope.base.ram.RamResource;
import com.yugao.fintech.framework.core.response.Resp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;

/**
 * 商户发起退款 controller
 */
@Slf4j
@RestController
@RequestMapping("/payMgt/refund")
public class RefundOrderMgtController {
    @Autowired
    private RefundOrderService refundOrderService;
    @Autowired
    private RefundOrderProcess refundOrderProcess;

    /**
     * 分页 退款
     */
    @GetMapping("/pageRefund")
    @RamResource(action = "pay:refund:list", name = "查询退款订单列表", type = ActionType.READ)
    public Resp<IPage<RefundOrderRS>> page(@Validated RefundOrderQL req) {
        return Resp.ok(refundOrderService.pageRefundOrder(req));
    }

    /**
     * 申请退款
     */
    @OperateLog(isSaveDb = false)
    @PostMapping("/refundOrder")
    @PayCheck
    @RamResource(action = "pay:refund:refundOrder", name = "申请退款", type = ActionType.WRITE)
    public Resp<?> refundOrder(@RequestBody @Validated RefundOrderRQ rq) {
        return refundOrderProcess.refundOrder(rq);
    }

}
